﻿using System;
using NDBGen.Descriptors.Columns.Tokens;

namespace NDBGen.Plugins.Descriptors.Columns.Tokens
{
    [ColumnTokenScriptSnippetGenerator(typeof(NullableTokenDescriptor))]
    public sealed class SqlServerNullableTokenScriptGenerator : SqlServerColumnTokenScriptSnippetGeneratorBase, IOrderedMetadata
    {
        private const String SQL_PRESENT = "null";
        private const String SQL_NOT_PRESENT = "not null";

        protected override void WriteSql(IIndentedTextWriter writer)
        {
            if (String.IsNullOrEmpty(this.Descriptor.TokenValue))
            {
                writer.Write(SQL_NOT_PRESENT);
            }
            else
            {
                writer.Write(SQL_PRESENT);
            }
        }

        Int32 IOrderedMetadata.GenerationIndex { get { return 0; } }
    }
}